﻿namespace D.Wx.AppsettingsUtil
{
    /// <summary>
    /// 配置加载封装
    /// </summary>
    public static class AppsettingsUtils
    {
        public static IConfiguration Configuration { get; internal set; }

        /// <summary>
        /// 获取配置实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Get<T>()
        {
            if (Configuration == null)
                return default(T);
            return Configuration.Get<T>();
        }

        /// <summary>
        /// 多个节点,通过.GetSection("key")["key1"]获取
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static IConfigurationSection Get(string key)
        {
            if (Configuration == null)
                return default;
            return Configuration?.GetSection(key);
        }

    }
}
